﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace helicopterFight
{
    /*
     *  Wysokościomierz znajdujący się w prawym dolnym rogu gry.
     *  Przechowuje referencję na helikopter z którego pobiera dane.
     */
    public class Altimeter
    {
        private Texture2D Altimeter1, Altimeter2;
        private Game1 game;
        private HelicopterObject heli;
        private const float scale = 0.5f;
        private int x, y;

        public Altimeter(Game1 game, HelicopterObject heli)
        {
            this.game = game;
            this.heli = heli;
            Altimeter1 = game.Content.Load<Texture2D>("indicators/altimeter1");     //Tarcza altimetera
            Altimeter2 = game.Content.Load<Texture2D>("indicators/altimeter2");     //Wskazówka altimetera
            x = game.graphics.PreferredBackBufferWidth - (int)(Altimeter1.Width * scale) / 2 - 20;
            y = game.graphics.PreferredBackBufferHeight - (int)(Altimeter1.Height * scale) / 2 - 20;
        }

        public void draw(SpriteBatch sb, Vector3 position)
        {
            sb.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
                sb.Draw(Altimeter1, new Vector2(x, y), new Rectangle(0, 0, Altimeter1.Width, Altimeter1.Height),
                    Color.White, 0 , new Vector2(Altimeter1.Width / 2, Altimeter1.Height / 2), 
                    scale, SpriteEffects.None, 0.0f);
                sb.Draw(Altimeter2, new Vector2(x, y), new Rectangle(0, 0, Altimeter2.Width, Altimeter2.Height),
                    Color.White, ((position.Y - heli.getMinAltitude()) / heli.getMaxAltitude())  // maxAltitude 
                    * 2 * (float)Math.PI, new Vector2(Altimeter2.Width / 2, Altimeter2.Height / 2), 
                    scale, SpriteEffects.None, 0.0f);

            sb.End();
        }
    }
}
